package com.epalmpay.controller.ys.memberRedActivity;

import com.epalmpay.commom.BaseController;
import com.epalmpay.dto.member.MemberInDTO;
import com.epalmpay.dto.member.MemberOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.yunliu.memberRedActivity.*;
import com.epalmpay.entity.Member;
import com.epalmpay.entity.Page;
import com.epalmpay.entity.YsObd;
import com.epalmpay.entity.YsOilcardMember;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.ys.memberRedActivityService.IYsMemberRedActivityService;
import com.epalmpay.status.Rescode;
import com.epalmpay.util.PropertyCopyUtil;
import com.epalmpay.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by gwn on 2018/1/9.
 */
@Controller
@RequestMapping(value="/channel/memberRedActivity")
public class MemberRedActivityController extends BaseController {

    @Resource
    private IYsMemberRedActivityService memberRedActivityService;

    @ResponseBody
    @RequestMapping(value = "/list")
    public MemberRedActivityListOutDTO list(MemberRedActivityInDTO memberRedActivityInDTO, PageDTO pageDTO)throws Exception{
        MemberRedActivityListOutDTO memberRedActivityListOutDTO = new MemberRedActivityListOutDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            memberRedActivityListOutDTO= memberRedActivityService.queryMemberRedActivityList(memberRedActivityInDTO,page);

            memberRedActivityListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            memberRedActivityListOutDTO.setPage(page);
            return memberRedActivityListOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberRedActivityListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberRedActivityListOutDTO;

    }
    @ResponseBody
    @RequestMapping(value = "/saveMemberRedActivity")
    public MemberRedActivityOutDTO saveMemberRedActivity(@RequestBody MemberRedActivityInDTO memberRedActivityInDTO)throws Exception{
        MemberRedActivityOutDTO memberRedActivityOutDTO = new MemberRedActivityOutDTO();
        try {
            memberRedActivityService.saveMemberRedActivity(memberRedActivityInDTO);

            memberRedActivityOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            return memberRedActivityOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberRedActivityOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberRedActivityOutDTO;

    }

    /**
     * 查看会员红利id  根基id huixian
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/view")
    @ResponseBody
    public MemberRedActivityOutDTO view( MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityOutDTO memberRedActivityOutDTO=new MemberRedActivityOutDTO();
        try {
            memberRedActivityOutDTO= memberRedActivityService.queryMemberRedActivityDetail(memberRedActivityInDTO);
            memberRedActivityOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
            return memberRedActivityOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityOutDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityOutDTO;
    }

    /**
     * 提前结束活动
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/editStatus")
    @ResponseBody
    public MemberRedActivityOutDTO editStatus( MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityOutDTO memberRedActivityOutDTO=new MemberRedActivityOutDTO();
        try {
            memberRedActivityOutDTO= memberRedActivityService.editStatus(memberRedActivityInDTO);
            memberRedActivityOutDTO.setErrorCode(Rescode.SUCCESS, "更新成功");
            return memberRedActivityOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityOutDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityOutDTO;
    }

    @ResponseBody
    @RequestMapping(value = "/queryPerfectDetailList")
    public MemberRedActivityPerfectListDTO queryPerfectDetailList(MemberRedActivityInDTO memberRedActivityInDTO, PageDTO pageDTO)throws Exception{
        MemberRedActivityPerfectListDTO memberRedActivityPerfectListDTO = new MemberRedActivityPerfectListDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            memberRedActivityPerfectListDTO= memberRedActivityService.queryPerfectDetailList(memberRedActivityInDTO,page);

            memberRedActivityPerfectListDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            memberRedActivityPerfectListDTO.setPage(page);
            return memberRedActivityPerfectListDTO;
        } catch (ApplicationException ae) {
            memberRedActivityPerfectListDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberRedActivityPerfectListDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberRedActivityPerfectListDTO;

    }


    /**
     * 提前结束活动
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/editRebateStatus")
    @ResponseBody
    public MemberRedActivityPerfectOutDTO editRebateStatus(MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityPerfectOutDTO memberRedActivityPerfectOutDTO=new MemberRedActivityPerfectOutDTO();
        try {
            memberRedActivityPerfectOutDTO= memberRedActivityService.editRebateStatus(memberRedActivityInDTO);
            memberRedActivityPerfectOutDTO.setErrorCode(Rescode.SUCCESS, "更新成功");
            return memberRedActivityPerfectOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityPerfectOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityPerfectOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityPerfectOutDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityPerfectOutDTO;
    }


    /**
     * 红利详情说明
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/queryPerfectView")
    @ResponseBody
    public MemberRedActivityPerfectListDTO queryPerfectView( MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityPerfectListDTO memberRedActivityPerfectListDTO=new MemberRedActivityPerfectListDTO();
        try {
            memberRedActivityPerfectListDTO= memberRedActivityService.queryPerfectView(memberRedActivityInDTO);
            memberRedActivityPerfectListDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
            return memberRedActivityPerfectListDTO;
        } catch (ApplicationException ae) {
            memberRedActivityPerfectListDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityPerfectListDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityPerfectListDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityPerfectListDTO;
    }


    /**
     * 提前返利
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/eralyRebate")
    @ResponseBody
    public MemberRedActivityPerfectOutDTO eralyRebate( MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityPerfectOutDTO memberRedActivityPerfectOutDTO=new MemberRedActivityPerfectOutDTO();
        try {
            memberRedActivityPerfectOutDTO= memberRedActivityService.eralyRebate(memberRedActivityInDTO);
            memberRedActivityPerfectOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
            return memberRedActivityPerfectOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityPerfectOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityPerfectOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityPerfectOutDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityPerfectOutDTO;
    }
    /**
     * 全部提前返利
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/batchEralyRebate")
    @ResponseBody
    public MemberRedActivityPerfectOutDTO batchEralyRebate( MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityPerfectOutDTO memberRedActivityPerfectOutDTO=new MemberRedActivityPerfectOutDTO();
        try {
            memberRedActivityPerfectOutDTO= memberRedActivityService.batchEralyRebate(memberRedActivityInDTO);
            memberRedActivityPerfectOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
            return memberRedActivityPerfectOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityPerfectOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityPerfectOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityPerfectOutDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityPerfectOutDTO;
    }


    /**
     * 查询正在进行中的红利活动
     * @param memberRedActivityInDTO
     * @return
     */
    @RequestMapping(value="/hasU")
    @ResponseBody
    public MemberRedActivityOutDTO hasU( MemberRedActivityInDTO memberRedActivityInDTO){
        MemberRedActivityOutDTO memberRedActivityOutDTO=new MemberRedActivityOutDTO();
        try {
            memberRedActivityOutDTO= memberRedActivityService.hasU(memberRedActivityInDTO);
            memberRedActivityOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
            return memberRedActivityOutDTO;
        } catch (ApplicationException ae) {
            memberRedActivityOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            memberRedActivityOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        memberRedActivityOutDTO.setErrorCode("-2", "处理失败");
        return memberRedActivityOutDTO;
    }





}



